<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;
use App\Models\User;

class Popover extends AbstractDisplayer
{
    public function display($placement = 'left')
    {
        Admin::script("$('[data-toggle=\"popover\"]').popover()");

        $user = User::where('username',$this->value)->first('pid');
        if($user->pid != 0){
            $first = User::where('id',$user->pid)->first();
            $content = '一级代理：'.$first->username ;
            if($first->pid != 0){
                $second = User::where('id',$first->pid)->first();
                $content.= ' 二级代理：'.$second->username;
            }
            $color = '#00a65a';
        }else{
            $content = '没有代理';
            $color = '#ddd';
        }
        return <<<EOT
<button type="button"
     style="background-color:$color"
    class="btn btn-secondary"
    title="代理展示"
    data-container="body"
    data-toggle="popover"
    data-placement="$placement"
    data-content="{$content}"
    >
  $this->value
</button>

EOT;

    }
}